from typing import Literal

from langchain_core.messages import HumanMessage
from langchain_core.tools import tool
from langchain_openai import ChatOpenAI


## 加一个@tool注解，创建一个工具; Literal 枚举封装
@tool
def weather_tool(weather: Literal["晴朗的","多云的","多雨的"]) -> None:
    """Describe the weather"""
    pass


image_url_1 = "https://...."
image_url_2 = "https://...."
model = ChatOpenAI(model="gpt-4o")
model_with_tools = model.bind_tools(weather_tool)
message = HumanMessage(
    content=[{"type": "text", "text": "用中文描述 这张图片中的天气"},
             {"type": "image_url", "image_url": {"url": image_url_1}},
             {"type": "image_url", "image_url": {"url": image_url_2}},
             ],
)
response = model_with_tools.invoke([message])
print(response.tool_calls)
